package com.jindy.module.oaEvectionApproval.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.module.oaDepartApproval.controller.SyOaDepartController;
import com.jindy.module.oaDepartApproval.domain.SyOaDepart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.module.oaEvectionApproval.domain.SyOaEvection;
import com.jindy.module.oaEvectionApproval.service.ISyOaEvectionService;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 出差申请Controller
 * 
 * @author jindy
 * @date 2023-05-31
 */
@RestController
@RequestMapping("/module/oaEvectionApproval")
public class SyOaEvectionController extends BaseController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(SyOaEvectionController.class);

    @Autowired
    private ISyOaEvectionService syOaEvectionService;

    /**
     * 查询出差申请列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaEvectionApproval:list')")
    @GetMapping("/list")
    public TableDataInfo list(SyOaEvection syOaEvection)
    {
        startPage();
        List<SyOaEvection> list = syOaEvectionService.selectSyOaEvectionList(syOaEvection);
        return getDataTable(list);
    }

    /**
     * 导出出差申请列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaEvectionApproval:export')")
    @Log(title = "出差申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyOaEvection syOaEvection)
    {
        List<SyOaEvection> list = syOaEvectionService.selectSyOaEvectionList(syOaEvection);
        ExcelUtil<SyOaEvection> util = new ExcelUtil<SyOaEvection>(SyOaEvection.class);
        util.exportExcel(response, list, "出差申请数据");
    }

    /**
     * 获取出差申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:oaEvectionApproval:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(syOaEvectionService.selectSyOaEvectionById(id));
    }

    /**
     * 新增出差申请
     */
    @PreAuthorize("@ss.hasPermi('module:oaEvectionApproval:add')")
    @Log(title = "出差申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyOaEvection syOaEvection)
    {
        return toAjax(syOaEvectionService.insertSyOaEvection(syOaEvection));
    }

    /**
     * 修改出差申请
     */
    @PreAuthorize("@ss.hasPermi('module:oaEvectionApproval:edit')")
    @Log(title = "出差申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyOaEvection syOaEvection)
    {
        return toAjax(syOaEvectionService.updateSyOaEvection(syOaEvection));
    }

    /**
     * 删除出差申请
     */
    @PreAuthorize("@ss.hasPermi('module:oaEvectionApproval:remove')")
    @Log(title = "出差申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(syOaEvectionService.deleteSyOaEvectionByIds(ids));
    }

    /**
     * 提交申请
     */
    @Log(title = "出差审批", businessType = BusinessType.UPDATE)
    @PostMapping( "/submitApply/{id}")
    @ResponseBody
    public AjaxResult submitApply(@PathVariable Long id) {
        try {
            SyOaEvection syOaEvection = syOaEvectionService.selectSyOaEvectionById(id);
            syOaEvectionService.submitApply(syOaEvection);
        } catch (Exception e) {
            LOGGER.error("出差审批提交申请出错",e);
            return error("出差审批提交申请出错：" + e.getMessage());
        }
        return success();
    }
}
